#include "stdafx.h"
#include <LitFileSystem.h>

#if LIT_BOOST_SUPPORT
#include <boost\filesystem.hpp>

namespace Lit
{	
	void FileSystem::_setApplicationPath( const String &str )
	{
		boost::filesystem::current_path( str.data() );
	}
	String FileSystem::applicationPath()
	{ 
		return boost::filesystem::current_path().string().c_str();
	}
	bool FileSystem::exists( const String &name ){
		return boost::filesystem::exists(name.data());
	}
	void FileSystem::removeAll( const String &path ){
		boost::filesystem::remove_all(path.data());
	}
	bool FileSystem::createDirectories( const String &path ){
		try
		{
			if( !boost::filesystem::is_directory( path.data() ) )
				boost::filesystem::create_directories( path.data() );
		}
		catch( ... )
		{
			return false;
		}
		return true;
	}
	String FileSystem::fileName( const String &path ){
		FilePath p (path);
		if( p.empty() ) return p;
		p.setTrailingSlash( false );
		return boost::filesystem::path(p.str().data()).filename().string().c_str();
	}
	String FileSystem::dirName( const String &path ){
		FilePath p (path);
		if( p.empty() ) return p;
		p.setTrailingSlash( false );
		String ret= boost::filesystem::path(p.str().data()).parent_path().string().c_str();
		return ret;
	}
	FilePath FileSystem::findResourcePath( const String &res_name )
	{
		// TODO Reimplement this !
		/*String resourceGroup;
		try{
			resourceGroup=Ogre::ResourceGroupManager::getSingletonPtr()->findGroupContainingResource(res_name);
		}catch(...){ return FilePath(); }
		Ogre::FileInfoListPtr fileInfoList(Ogre::ResourceGroupManager::getSingletonPtr()->findResourceFileInfo(resourceGroup, res_name));
		if( fileInfoList->empty() )
			return FilePath();
		Ogre::FileInfo &p(fileInfoList->at(0));
		if( !p.filename.empty() )
		{
			if( p.archive )
			{
				return FilePath(p.archive->getName()+"/"+p.filename);
			}
		}*/
		return FilePath();
	}
};

#endif